package com.jy.modules.cims.component.settle;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.common.JResult;
import com.jy.modules.cims.component.common.service.TCMmCooperorgDealService;
import com.jy.modules.cims.data.common.dto.TCMmCooperorgDealDTO;

@Service("com.jy.modules.cims.component.settle.CSettleConcreteVisitor")
public class CSettleConcreteVisitor implements ICSettle {

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmCooperorgDealService")
	private TCMmCooperorgDealService tCMmCooperorgDealService;

	/**
	 * 
	 */
	public JResult settle(String bizCode) throws Exception {
		JResult result = new JResult();
		result.setSuccess(false);

		Map<String, Object> paramMap = new HashMap<String, Object>();
		TCMmCooperorgDealDTO tCMmCooperorgDealDTO = new TCMmCooperorgDealDTO();
		String message = "";

		tCMmCooperorgDealDTO.setDealCode(bizCode);
		paramMap.put("dto", tCMmCooperorgDealDTO);
		List<TCMmCooperorgDealDTO> tCMmCooperorgDealList = tCMmCooperorgDealService
				.searchTCMmCooperorgDeal(paramMap);
		if (null == tCMmCooperorgDealList || tCMmCooperorgDealList.size() == 0) {
			result.setErrCode(ERROR_CODE_00000001);
			message = MessageFormat.format(ERROR_MESSAGE_00000001,
					new Object[] { bizCode });
			result.setErrMsg(message);
			return result;
		}

		tCMmCooperorgDealDTO = tCMmCooperorgDealList.get(0);
		String contractCode = tCMmCooperorgDealDTO.getContractCode();// 合约编号
		// 根据合约编号编号查询合约参数，计算金额
		// 费用结算 T_C_MM_COST_ACCOUNT：增加一条数据
		// 费用结算明细 T_C_MM_COST_ACCOUNTDATIAL：如果费用结算参数有多条记录，需要有明细
		return result;
	}

}
